<template>
	<view scroll-with-animation scroll-y 
		style="height:100%;position: relative;background-color: #F8FBFB;padding-bottom: 40rpx;">
		<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;">
			<view class="card-row">
				<view><text style="font-weight: bolder;">医院:</text>{{medicalrecord.hspName}}</view>
				<view><text style="font-weight: bolder;">就诊医生：</text>{{medicalrecord.attendingphysician}}</view>
			</view>
			<view class="card-row" style="margin-top: 40rpx;">
				<view><text style="font-weight: bolder;">科室：</text>{{medicalrecord.treatDeptName}}</view>
				<view><text style="font-weight: bolder;">入院时间：</text>{{medicalrecord.updatedate}}</view>
			</view>
		</view>
		<view class="card">
			<view class="card-head">诊断结果:</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.outpatientdiagnosis}}</view>
		</view>
		<view class="card">
			<view class="card-head">主诉：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.cheifcomplaint}}</view>
		</view>
		<view class="card">
			<view class="card-head">现病史：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.historypresentillness}}</view>
		</view>
		<view class="card">
			<view class="card-head">既往史：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.pastdiseasehistory}}</view>
		</view>
		<view class="card">
			<view class="card-head">过敏史：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.allergicHistory}}</view>
		</view>
		
		<view class="card">
			<view class="card-head">婚育史：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.obstetricalhistory}}</view>
		</view>
		<view class="card">
			<view class="card-head">家族史：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.familyhistory}}</view>
		</view>
		<view class="card">
			<view class="card-head">其他：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.otherHistory}}</view>
		</view>
		<view class="card">
			<view class="card-head">体格检查：</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.physicalexamination}}</view>
		</view>
		<view class="pt30 pb30">
			<view class="add-btn" @click="exportPDF">导出为图片</view>
		</view>
		
		<view v-if='isSaveing' style="position: fixed;height: 100%;
			width: 100%;background-color: rgba(8, 8, 7, 0.5);z-index: 999;top:0rpx;left: 0rpx;display: flex;align-items: center;justify-content: center;">
			<icon type="waiting" size="26"/>
			<text style="color: #FFFFFF;margin-left: 20rpx;font-size: 38rpx;">图片导出中...</text>
		</view>
		
		
		<view class="win flex" v-if="isShowDown" @touchmove.stop="">
			<view style="margin: auto;background-color: #FFFFFF;border-radius: 20rpx;width: 80%;height: 400rpx;display: flex;flex-direction: column;align-items: center;justify-content: space-around;">
				<!-- <view style="font-size: 36rpx;text-align: center;font-weight: bold;">订阅消息</view> -->
				<view style="font-size: 30rpx;text-align: center;">导出成功,是否保存到本地？</view>
				<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;align-items: center;width: 100%;">
					<button type='primary' style="background-color: #F3F3F3;width: 40%;color: #000000;height: 90rpx;line-height: 90rpx;font-size: 30rpx;" @click="isShowDown=false">
						取消
					</button>
					<button type='primary' style="background-color: #1BC1B6;width: 40%;height: 90rpx;line-height: 90rpx;font-size: 30rpx;" @click="pdfDown">
						确定
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				medicalrecord:undefined,
				isSaveing: false,
				isShowDown: false,
				pdfUrl:undefined
			};
		},
		onLoad(option) {
			this.medicalrecord = uni.getStorageSync('medicalrecord')
		},
		methods:{
			exportPDF(){
				if(this.isSaveing){
					return
				}
				this.isSaveing = true
				this.func.$request('wx/medicalRecordDownload.tz',{id : this.medicalrecord.medcalRecordId},"GET").then(res=>{
					if(res.data.success){
						this.pdfUrl = res.data.result
						this.isShowDown = true
					}
				})
			},
			pdfDown(){
				this.isShowDown = false
				uni.downloadFile({
					url: this.pdfUrl, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: '保存成功',
										icon: 'none',
										duration:2000,
										mask:true
									});
								},
								fail: function() {
									uni.showToast({
										title: '保存失败',
										icon: 'none'
									});
								}
							});
						}
					}
				});
			}
		}
	};
</script>

<style lang="less">
	.card-row{
		width: calc(100% - 40rpx);
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
	}
	.card-head{
		font-size: 30rpx;
		font-weight: bolder;
		width: calc(100% - 40rpx);
		border-bottom: 2rpx solid #E1E1E1;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
	.card{
		background-color: #FFFFFF;
		padding-left: 40rpx;
		margin-top: 20rpx;
		padding-bottom: 20rpx;
	}
	.add-btn{
		margin: auto;
		height: 88rpx;
		line-height: 88rpx;
		width: 90%;
		background: linear-gradient(90deg, #23E0D3 0%, #00BAAD 100%);
		box-shadow: 0px 20rpx 25rpx 0px rgba(0, 186, 173, 0.4);
		border-radius: 44rpx;
		color: #FFFFFF;
		text-align: center;
	}
	.win {
		position: fixed;
		width: 100%;
		height: 100vh;
		left: 0;
		top: 0;
		z-index: 20;
		background: rgba(0, 0, 0, 0.3);
	
		scroll-view {
			height: 100vh;
			background: #fff;
	
			view {
				height: 90rpx;
				line-height: 90rpx;
				border-bottom: 1rpx solid #EFEFEF;
				position: relative;
			}
	
			view.active::after {
				position: absolute;
				content: '';
				width: 65rpx;
				height: 10rpx;
				background: #74a6fd;
				left: 50%;
				margin-left: -32rpx;
				top: 65%;
			}
		}
	}
</style>
